package com.syf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syf.mapper.TurnoverOrderMapper;
import com.syf.domain.TurnoverOrder;
import com.syf.service.TurnoverOrderService;
/**
*
*
*@author syf
*@create 2021-11-17 14:13
*/
@Service
public class TurnoverOrderServiceImpl extends ServiceImpl<TurnoverOrderMapper, TurnoverOrder> implements TurnoverOrderService{

    /**
     * 1.前台--资产管理--成交记录的查询【有点问题】
     *
     * @param page
     * @param userId
     * @param symbol
     * @param type
     * @return
     */
    @Override
    public Page<TurnoverOrder> findByPage(Page<TurnoverOrder> page, Long userId, String symbol, Integer type) {
        /*return page(page,new LambdaQueryWrapper<TurnoverOrder>()
                .eq(TurnoverOrder::getBuyUserId, userId)
                .eq(StringUtils.isNotEmpty(symbol),TurnoverOrder::getSymbol, symbol)
                .eq(type != null, TurnoverOrder::getTradeType, type)
        );*/
        return null;
    }

    /**
     * 2.获取买入的订单的成功的记录
     *
     * @param orderId
     * @param userId
     * @return
     */
    @Override
    public List<TurnoverOrder> getBuyTurnoverOrder(Long orderId, Long userId) {
        return list(new LambdaQueryWrapper<TurnoverOrder>()
                .eq(TurnoverOrder::getOrderId, orderId)
                .eq(TurnoverOrder::getBuyUserId, userId)
        );
    }

    /**
     * 3.获取卖出订单的成交记录(orderId, userId)
     *
     * @param orderId
     * @param userId
     * @return
     */
    @Override
    public List<TurnoverOrder> getSellTurnoverOrder(Long orderId, Long userId) {
        return list(new LambdaQueryWrapper<TurnoverOrder>().eq(TurnoverOrder::getOrderId, orderId)
                .eq(TurnoverOrder::getSellUserId, userId)
        );
    }

    /**
     * 4.查询成交记录(交易对symbol)
     *
     * @param symbol
     * @return
     */
    @Override
    public List<TurnoverOrder> findBySymbol(String symbol) {
        return list(new LambdaQueryWrapper<TurnoverOrder>()
                .eq(StringUtils.isNotEmpty(symbol), TurnoverOrder::getSymbol, symbol)
                .orderByDesc(TurnoverOrder::getCreated)
                .eq(TurnoverOrder::getStatus,1)  //已成交
                .last("limit 60")
        );
    }
}
